package com.example.springboot.exceptionInfo.impl;

import com.example.springboot.enumInfo.EnumInfoType;
import com.example.springboot.enumInfo.impl.EnumResult;
import com.example.springboot.exceptionInfo.ExceptionInfoType;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * @Description TODO 业务层异常处理
 */
@Slf4j
public class ExceptionBusiness extends ExceptionInfoType {

    /**
     * 构造方法
     */
    private ExceptionBusiness(String code, String msg) {
        super(code, msg);
    }

    //=====================================================================
    public static ExceptionInfoType getIntance(EnumInfoType eit, String msg) {
        String msgTemp = eit.getMsg() + (StringUtils.isNotBlank(msg) ? "，具体原因：" + msg : "");
        return new ExceptionBusiness(eit.getCode(), msgTemp);
    }

    public static ExceptionInfoType getIntance(EnumInfoType eit) {
        return getIntance(eit, "");
    }

    public static ExceptionInfoType getIntance() {
        return getIntance(EnumResult.FAILED);
    }

    public static ExceptionInfoType getIntanceFmt(EnumInfoType eit, Object... arguments) {
        return new ExceptionBusiness(eit.getCode(), String.format(eit.getMsg(), arguments));
    }
    //=====================================================================
}
